#include "data.h"
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

boolean prop = false;

boolean isvariable(char* s) {
    return (((s[0] >= 'U')&&(s[0] <= 'Z'))||((s[0] >= 'u')&&(s[0] <= 'z')));
}

boolean isfunction(char* s) {
    return (!isvariable(s) && (strchr(s,'(') != NULL));
}

boolean isconstant(char* s) {
    return ((!isvariable(s))&&(strchr(s,'(') == NULL));
}

boolean isalphanum(char c) {
    return (((c >= '0')&&(c <= '9'))||((c >= 'a') && (c <= 'z'))||((c <= 'Z') && (c >= 'A')));
}

void print_tree(address X) {
    if (Operator(X) == 'f') printf("%s",Isi(X));
    else if (Operator(X) == 'n') printf("-%s",Isi(X));
    else if (Operator(X) == '&' || (Operator(X) == '|')) {
        printf("(");
        print_tree(Left(X));
        printf(" %c ",Operator(X));
        print_tree(Right(X));
        printf(")");
    } else if (Operator(X) == '-') {
        printf("-(");
        print_tree(Left(X));
        printf(")");
    } else if (Operator(X) == '>') {
        printf("(");
        print_tree(Left(X));
        printf(" -> ");
        print_tree(Right(X));
        printf(")");    
    } else if (Operator(X) == '<') {
        printf("(");
        print_tree(Left(X));
        printf(" <- ");
        print_tree(Right(X));
        printf(")");    
    } else if (Operator(X) == '=') {
        printf("(");
        print_tree(Left(X));
        printf(" <-> ");
        print_tree(Right(X));
        printf(")");    
    } else if (Operator(X) == 'a') {
        printf("All %s (",Isi(X));
        print_tree(Left(X));
        printf(")");    
    } else if (Operator(X) == 'e'){
        printf("Exists %s (",Isi(X));
        print_tree(Left(X));
        printf(")");       
    }
}

void print_clause(int indeks, int tipe, int nomor) {
    int i;
    printf("O : {%s",clauses[indeks][0]);
    for (i=1;i<member[indeks];++i) printf(" , %s",clauses[indeks][i]);
    printf("} [%s %d]\n",tipe==0?"premis":"negated goal",nomor);
}
